Imports Microsoft.VisualBasic
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports EntityLayer

Public Class DetalleOrdenCompraDA

    Public Shared Function Agregar(ByVal intOrdenCompra As Integer, ByVal DetalleOrdenCompraEN As DetalleOrdenCompra) As Boolean
        Try
            Dim myConnection As New SqlConnection(ConexionDA.ObtenerCnx)
            Dim myCommand As New SqlCommand("usp_AddDetalleOrdenCompra", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure

            Dim para As SqlParameter

            para = New SqlParameter("@intNroOrden", SqlDbType.Int)
            para.Direction = ParameterDirection.Input
            para.Value = intOrdenCompra
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@intItem", SqlDbType.Int)
            para.Direction = ParameterDirection.Input
            para.Value = DetalleOrdenCompraEN.Item
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@intCantidad", SqlDbType.Int)
            para.Direction = ParameterDirection.Input
            para.Value = DetalleOrdenCompraEN.Cantidad
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@strDescripcion", SqlDbType.VarChar, 100)
            para.Direction = ParameterDirection.Input
            para.Value = DetalleOrdenCompraEN.Descripcion
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@flTotalProducto", SqlDbType.Decimal)
            para.Direction = ParameterDirection.Input
            para.Value = DetalleOrdenCompraEN.MontoTotal
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@intIdProducto", SqlDbType.Int)
            para.Direction = ParameterDirection.Input
            para.Value = DetalleOrdenCompraEN.CodigoProducto
            myCommand.Parameters.Add(para)


            myConnection.Open()
            myCommand.ExecuteNonQuery()
            myConnection.Close()

            Return True
        Catch ex As Exception
            Dim E As String = ex.Message
            Return False
        End Try

    End Function

    Public Shared Function Eliminar(ByVal intOrdenCompra As Integer) As Boolean
        Try
            Dim myConnection As New SqlConnection(ConexionDA.ObtenerCnx)
            Dim myCommand As New SqlCommand("COM_DetalleOrdenCompra_Del", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure

            Dim para As SqlParameter

            para = New SqlParameter("@intNroOrden", SqlDbType.Int)
            para.Direction = ParameterDirection.Input
            para.Value = intOrdenCompra
            myCommand.Parameters.Add(para)

            myConnection.Open()
            myCommand.ExecuteNonQuery()
            myConnection.Close()

            Return True
        Catch ex As Exception
            Dim E As String = ex.Message
            Return False
        End Try

    End Function

    Public Shared Function ListarDetalleCompraxCodigo(ByVal intIdOrden As Integer) As DataSet

        Dim cnnSql As New SqlConnection(ConexionDA.ObtenerCnx)
        Dim daSql As New SqlDataAdapter("COM_DetalleOrdenCompra_ListByCodigo", cnnSql)
        daSql.SelectCommand.CommandType = CommandType.StoredProcedure

        Dim dsDatos As New DataSet

        daSql.SelectCommand.Parameters.Add("@intIdOrden", SqlDbType.Int).Value = intIdOrden

        daSql.Fill(dsDatos, "OrdenCompra")

        Return dsDatos

    End Function

End Class
